<?php
include_once($_SERVER['DOCUMENT_ROOT']."/config.php");
include_once($gDOCUMENT_ROOT_SYSTEM.'include/dao/db.php');
class film_release_on_blu_ray
{
	private $db;
	private $table_name = 'film_release_on_blu_ray';
	function __construct()
	{
		$this->db = new db();
	}
	public function insert($data)
	{
		if(!isset($data['film_id'])||empty($data['film_id']))
		{
			return false;
		}
		$data_for_query['film_id'] = intval($data['film_id']);
		if(isset($data['area'])&&!empty($data['area']))
		{
			$data_for_query['area'] = intval($data['area']);
		}
		if(isset($data['video_bitrate'])&&!empty($data['video_bitrate']))
		{
			$data_for_query['video_bitrate'] = intval($data['video_bitrate']);
		}
		if(isset($data['date'])&&!empty($data['date']))
		{
			$data_for_query['date'] = $data['date'];
		}
		if(isset($data['resolution_height'])&&!empty($data['resolution_height']))
		{
			$data_for_query['resolution_height'] = intval($data['resolution_height']);
		}
		if(isset($data['resolution_width'])&&!empty($data['resolution_width']))
		{
			$data_for_query['resolution_width'] = intval($data['resolution_width']);
		}
		if(isset($data['runtime'])&&!empty($data['runtime']))
		{
			$data_for_query['runtime'] = intval($data['runtime']);
		}
		if(isset($data['type'])&&!empty($data['type']))
		{
			$data_for_query['type'] = intval($data['type']);
		}
		$sql = "INSERT INTO `".$this->table_name."` (".$this->db->implodeToColumn(array_keys($data_for_query)).") VALUES (".$this->db->implodeToValues(array_values($data_for_query)).")";
		$count = $this->db->query($sql);
		if(empty($count))
		{
			//throw new Exception("INSERT INTO `".$this->table_name."` faild");
			throw new Exception("");
		}
		else
		{
			return $count;
		}
	}
	
	public function select($where,$column='*')
	{
		$sql_1 = "SELECT ".$this->db->implodeToColumn($column)." FROM ".$this->table_name." WHERE ".$this->db->implodeToWhere($where);
		$result_1 = $this->db->query($sql_1);
		$result_1->setFetchMode(PDO::FETCH_ASSOC);
		$fetch_result = $result_1->fetchAll();
		if($fetch_result==false)
		{
			//throw new Exception("faild");
			throw new Exception("");
		}
		else
		{
			return $fetch_result;
		}
	}
	
	public function getByFilmId($film_id,$column='*')
	{
		$where = array('film_id'=>$film_id);
		$result = $this->select($where,$column);
		foreach($result as $value)
		{
			$id_value[$value['id']] = $value;
		}
		return $id_value;
	}
}

?>
